package com.ruoyi.resume.domain.model;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Category {
    private Integer id;
    private Integer parentId;
    private String name;
    private String algorithmIdentifier;
    private String args;
    private Integer level;
    private Boolean isLastLevel;

    private List<Category> children; // 子分类
    private List<Tag> tags; // 标签

    // 解析 JSON 的方法
    public Map<String, List<String>> getArgsAsMap() {
        if (args == null || args.isEmpty()) {
            return new HashMap<>();
        }
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            return objectMapper.readValue(args, new TypeReference<Map<String, List<String>>>() {});
        } catch (Exception e) {
            e.printStackTrace();
            return new HashMap<>();
        }
    }
}
